package com.example.demo.Controller;


import com.example.demo.Entity.Message;
import com.example.demo.Entity.Result;
import com.example.demo.Service.MessageService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping("/add")
    public void Insert(@RequestBody Message message) {
        messageService.Insert(message);
    }

    @DeleteMapping("/delete")
    public Result Delete(@RequestBody Message message) {
        Message message0 = messageService.Get(message.getId());
        if (message0 == null) {
           return Result.error("不存在当前好友请求");
        } else {
            messageService.Delete(message.getId());
            return Result.success();
        }
    }
    @PostMapping
    public void Update(@RequestBody Message message) {
        messageService.Update(message);
    }

    @GetMapping("/select")
    public List<Message> Select(@RequestParam Integer receiveId) {
     return    messageService.Search(receiveId);
    }

    @DeleteMapping("/Delete")
    public void deleteApply(@RequestParam Integer sendId,@RequestParam Integer receiveId){
        messageService.deleteMessage(sendId,receiveId);
    }

    @GetMapping("/selectdialogue")
    public List<Message> SelectDialogue(@RequestParam Integer sendId,@RequestParam Integer receiveId) {
        return    messageService.SearchDialogue(sendId,receiveId);
    }

    @DeleteMapping("/deletebyid")
    public void deleteById(@RequestParam Integer Id){
        messageService.deleteById(Id);
    }






}
